package modellayer;

import java.util.ArrayList;

/**
 * The customer class to create customer objects
 * @author Allan Eriksen, Andreas Rye, Casper Madsen, Christian Stidsborg, Stefan Bols
 */

public class Order {
	private int orderNo;
	private String date;
	private double amount;
	private String deliveryStatus;
	private String deliveryDate;
	private Customer customerObj;
	private ArrayList<PartOrder> partOrderObj;
	private Invoice invoiceObj;
	private boolean isDummy;
	/**
	 * Order fields
	 * @param orderNo
	 * @param date
	 * @param amount
	 * @param deliveryStatus
	 * @param deliveryDate
	 * @param customerObj
	 * @param partOrderObj
	 * @param invoiceObj
	 */
	public Order()
	{
		
	
	}
	/**
	 * Constructor for the order class
	 */
	public Order(int orderNo, String date, double amount,
			String deliveryStatus, String deliveryDate, Customer customerObj,
			ArrayList<PartOrder> partOrderObj, Invoice invoiceObj) {
		super();
		this.orderNo = orderNo;
		this.date = date;
		this.amount = amount;
		this.deliveryStatus = deliveryStatus;
		this.deliveryDate = deliveryDate;
		this.customerObj = customerObj;
		this.partOrderObj = partOrderObj;
		this.invoiceObj = invoiceObj;
		this.isDummy = false;
	}
	
	/**
	 * Order dummy for the database layer
	 * @param orderNo
	 */
	public Order(int orderNo) {
		this.orderNo = orderNo;
		this.isDummy = true;
	}
	/**
	 * @param orderNo the orderNo to set
	 */
	public void setOrderNo(int orderNo) {
		this.orderNo = orderNo;
	}
	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}
	/**
	 * @param date the date to set
	 */
	public void setDate(String date) {
		this.date = date;
	}
	/**
	 * @return the amount
	 */
	public double getAmount() {
		return amount;
	}
	/**
	 * @param amount the amount to set
	 */
	public void setAmount(double amount) {
		this.amount = amount;
	}
	/**
	 * @return the deliveryStatus
	 */
	public String getDeliveryStatus() {
		return deliveryStatus;
	}
	/**
	 * @param deliveryStatus the deliveryStatus to set
	 */
	public void setDeliveryStatus(String deliveryStatus) {
		this.deliveryStatus = deliveryStatus;
	}
	/**
	 * @return the deliveryDate
	 */
	public String getDeliveryDate() {
		return deliveryDate;
	}
	/**
	 * @param deliveryDate the deliveryDate to set
	 */
	public void setDeliveryDate(String deliveryDate) {
		this.deliveryDate = deliveryDate;
	}
	/**
	 * @return the customerObj
	 */
	public Customer getCustomerObj() {
		return customerObj;
	}
	/**
	 * @param customerObj the customerObj to set
	 */
	public void setCustomerObj(Customer customerObj) {
		this.customerObj = customerObj;
	}
	/**
	 * @return the partOrderObj
	 */
	public ArrayList<PartOrder> getPartOrderObj() {
		return partOrderObj;
	}
	/**
	 * @param partOrderObj the partOrderObj to set
	 */
	public void setPartOrderObj(ArrayList<PartOrder> partOrderObj) {
		this.partOrderObj = partOrderObj;
	}
	public void addPartOrderObj(PartOrder obj) {
		if (this.partOrderObj==null) {
			this.partOrderObj = new ArrayList<PartOrder>();
		}
		this.partOrderObj.add(obj);
	}
	/**
	 * @return the invoiceObj
	 */
	public Invoice getInvoiceObj() {
		return invoiceObj;
	}
	/**
	 * @param invoiceObj the invoiceObj to set
	 */
	public void setInvoiceObj(Invoice invoiceObj) {
		this.invoiceObj = invoiceObj;
	}
	
	/**
	 * @return the isDummy
	 */
	public boolean isDummy() {
		return this.isDummy;
	}
	
	public void removePartOrder(String barcode) {
		boolean found = false;
		int i = 0;
		
		while (i < partOrderObj.size() && !found) {
			if (barcode.equals(partOrderObj.get(i).getProductObj().getBarcode())) {
				partOrderObj.remove(i);
				found = true;
			}
			
			i++;
		}
	}

	public double getFullAmount() {
		double amount = 0;
		
		for (PartOrder partOrder : partOrderObj) {
			amount+=partOrder.getAmount();
		}
		
		return amount;
	}
}
